﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Project.Ycm20250401.Service._20250418
{
    /// <summary>
    /// 用户注册
    /// </summary>
    /// <param name="Name"></param>
    /// <param name="Phone"></param>
    /// <param name="Email"></param>
    /// <param name="Password"></param>
    public  record  UserRegister(string Name, string Phone, string Email, string Password)
    {
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="name"></param>
        /// <param name="phone"></param>
        /// <param name="email"></param>
        /// <param name="password"></param>
        /// <param name="validatePassword"></param>
        /// <returns></returns>
        /// <exception cref="ArgumentException"></exception>
        public static async Task<UserRegister> AddUser(string name, string phone, string email, string password, IValidatePassword validatePassword)
        {
            if (string.IsNullOrEmpty(name))
            {
                throw new ArgumentException("用户名不能为空！");
            }
            if (string.IsNullOrEmpty(phone))
            {
                throw new ArgumentException("手机号不能为空！");
            }
            if (string.IsNullOrEmpty(email))
            {
                throw new ArgumentException("邮箱不能为空！");
            }
            if (string.IsNullOrEmpty(password))
            {
                throw new ArgumentException("密码不能为空！");
            }
            return new UserRegister(name, phone, email, await validatePassword.EncryptPassword(password));
        }
    }
}
